package com.jt.aop;

import com.fasterxml.jackson.databind.util.JSONPObject;
import com.jt.vo.SysResult;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

//定义全局异常的处理机制
@RestControllerAdvice
public class SystemAOP {
    @ExceptionHandler({RuntimeException.class})
    public Object result(Exception e, HttpServletRequest request){
    e.printStackTrace();
    String callback=request.getParameter("callback");
    if (StringUtils.hasLength(callback)){
        return new JSONPObject(callback, SysResult.fail());
    }
    return SysResult.fail();
    }

}
